package com.atguigu.test.dacahngmainshitidierji;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.concurrent.atomic.AtomicReference;

/**
 * 2 * @Author: madonghui
 * 3 * @Date: 2020/11/3 17:48
 * 4
 */
@Data
@AllArgsConstructor
class Human{
    private String name;
    private int age;
}
public class CasAtomicReference {
    public static void main(String[] args) {
        Human zhangsan = new Human("张三",1);
        Human lisi = new Human("李四",2);
        AtomicReference<Human> atomicReference = new AtomicReference<>(zhangsan);

        //比较并交换
        System.out.println("atomicReference.compareAndSet(zhangsan,lisi) = " + atomicReference.compareAndSet(zhangsan, lisi));
        System.out.println("atomicReference.get() = " + atomicReference.get());
        //再比较交换
        System.out.println("atomicReference.compareAndSet(zhangsan,lisi) = " + atomicReference.compareAndSet(zhangsan, lisi));
        System.out.println("atomicReference.get() = " + atomicReference.get());
    }
}
